"use strict";
/* Controllers */
app.controller("contentItemController",
    ['$scope', '$location', '$rootScope', '$routeParams', 'contentItemService',
    function ($scope, $location, $rootScope, $routeParams, contentItemService) {


    var vm = $scope.vm = {};

    vm.p = {};
    vm.result = {};
    vm.p.type = $routeParams.type;
    if(vm.p.type=='id') {
        vm.p.id = $routeParams.id;
    }else {
        vm.p.topicTbl = $routeParams.id;
    }

    var errorFn = function (result) {
        alert(result);
    };

    $scope.getMetricTopic = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        // 请求参数

        var params = {
            id: vm.p.id,
            demandSide:vm.p.demandSide,//需求方
            responsiblePerson:vm.p.responsiblePerson,//负责人
            requirementChange:vm.p.requirementChange,//需求变更
            doc:vm.p.doc,//需求文档
            onlineTime:vm.p.onlineTime,//上线时间
            sla:vm.p.sla,//服务等级SLA
            storeType:vm.p.storeType,//存储形式
            dbMessage:vm.p.dbMessage,//DB信息
            comment:vm.p.comment,//备注说明
            dataResultDescription:vm.p.dataResultDescription,//数据结果说明
            indexDimension:vm.p.indexDimension,//指标维度
            indicatorDescription:vm.p.indicatorDescription,//指标说明
            querySampleData:vm.p.querySampleData ,//数据样例查询
            sampleObtained:vm.p.sampleObtained//获取样例
        };

        // 结果处理
        var procFn = function (response) {
            if ("000" !== response.code) {
                alert(response.message);
                return ;
            }
            var data= response.data[0];
            if (data == null) {
                return;
            }
            vm.result.data = data;
            vm.p.id = data.id;
           $('#list_table').bootstrapTable('load', vm.result.data);
        };
        contentItemService.getMetricTopic(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageItem: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
       $scope.getMetricTopic();
    };
    $scope.initializeController();
}]);


/* Services */
app.service('contentItemService', ['ajaxService', function (ajaxService) {
    this.getMetricTopic = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/data_content/listMetricServiceEntity.do", successFunction, errorFunction);
    };
}]);


function topicTblIdOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="https://dp.58corp.com/data-content/detail-page/', row.topicTblId,'" target="_blank">', "<u>DP详情</u>" , '</a>'
    ].join('');
}